package com.yxt.shecaiyun.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yxt.shecaiyun.dto.userDto.UserQueryDTO;
import com.yxt.shecaiyun.entity.Club;
import com.yxt.shecaiyun.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("SELECT * FROM user WHERE user_account = #{account}")
    User selectByAccount(String account);
    @Select("""
        SELECT * FROM user
        WHERE 1=1
        <if test='query.account != null and query.account != ""'>
            AND user_account LIKE CONCAT('%', #{query.account}, '%')
        </if>
        <if test='query.major != null and query.major != ""'>
            AND user_major = #{query.major}
        </if>
        ORDER BY id DESC
        LIMIT #{pageSize} OFFSET #{offset}
        """)
    List<User> selectUserList(
            @Param("query") UserQueryDTO query,
            @Param("offset") Long offset,
            @Param("pageSize") Integer pageSize
    );

    @Select("""
        SELECT COUNT(*) FROM user
        WHERE 1=1
        <if test='query.account != null and query.account != ""'>
            AND user_account LIKE CONCAT('%', #{query.account}, '%')
        </if>
        <if test='query.major != null and query.major != ""'>
            AND user_major = #{query.major}
        </if>
        """)
    Long countUserList(@Param("query") UserQueryDTO query);
}